# frozen_string_literal: true

class CreateSchemaVariables < ActiveRecord::Migration[6.0]
  def change
    create_table :schema_variables do |t|
      t.integer :schema_id,         null: false,  limit: 8
      t.integer :variable_type_id,  null: false,  limit: 8
      t.string  :name,              null: false,  limit: 64
      t.integer :ordinal,           null: false,  limit: 4
      t.string  :io_type,           null: false,  limit: 16
      t.boolean :required,          null: false,  default: false
      t.string  :default_value,     null: true, limit: 255
      t.timestamps                  null: false
    end

    add_index :schema_variables, %i[ordinal io_type schema_id], unique: true
    add_index :schema_variables, %i[io_type name schema_id], unique: true
    add_foreign_key :schema_variables, :schemas
    add_foreign_key :schema_variables, :variable_types
  end
end
